/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.game.entity.body;

import ace.system.Utilities;
import ace.system.xml.XmlNode;
import ace.system.xml.XmlReaderWriter;
import java.util.Hashtable;

/**
 *
 * @author Hallucinogen
 */
public class BodyFactory {
	private BodyFactory() {
		mBodyDictionary = new Hashtable();
		XmlNode XML = XmlReaderWriter.getInstance().readFromXmlFile(Utilities.BODY_FILE);

		//For each child
		for (int i = 0; i < XML.getChildren().size(); i++) {
			//Get child
			XmlNode Child = (XmlNode)XML.getChildren().elementAt(i);

			//Check name
			if (Child.getNodeName().equals("body")) {
				//Prepare variable
				int j		= 0;
				int Index	= Integer.parseInt(Child.getAttribute("index"));

				//Save to dictionary
				if (Index >= 0) mBodyDictionary.put(new Integer(Index), new BodyData(Child));
			}
		}
	}

	public static BodyFactory instance() {
		if (sInstance == null) {
			sInstance = new BodyFactory();
		}
		return sInstance;
	}

	public BodyData getBodyData(int index) {
		return (BodyData)mBodyDictionary.get(new Integer(index));
	}

	private Hashtable mBodyDictionary;

	// singleton
	private static BodyFactory sInstance = null;
}
